package com.asia.algorithmcode.array;

/**
 * 137、只出现一次的数字2,除此之外的数字都出现了3次
 */
public class SingleNumber2 {


    public static void main(String[] args) {
        int[] arr = {2,2,3,2};
        System.out.println(new SingleNumber2().singleNumber(arr));
    }

    public int singleNumber(int[] nums) {
        int[] counts = new int[32];
        for (int num : nums) {
            for (int i = 0; i < 32; i++) {
                counts[i] += (num >> i) & 1;
            }
        }

        int ans = 0;
        for (int i = 0; i < 32; i++) {
            if (counts[i] % 3 != 0) {
                ans |= 1 << i;
            }
        }

        return ans;
    }
}
